//
//  LLModel.m
//  lrlzapp
//
//  Created by dl on 16/2/24.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLModel.h"

void JSONArrayToModelArrayError(Class cls, NSError **error, id jsonArray) {
    NSDictionary *userInfo =
            @{
                    NSLocalizedDescriptionKey : [NSString stringWithFormat:@"JSON数组转Model数组失败, modelClass:%@", NSStringFromClass(cls)],
                    NSLocalizedFailureReasonErrorKey : @"",
                    MTLTransformerErrorHandlingInputValueErrorKey : jsonArray
            };

    *error = [NSError errorWithDomain:MTLTransformerErrorHandlingErrorDomain
                                 code:MTLTransformerErrorHandlingErrorInvalidInput
                             userInfo:userInfo];
}

void ModelArrayToJsonArrayError(Class cls, NSError **error, id modelArray) {
    NSDictionary *userInfo =
            @{
                    NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Model数组转JSON数组失败, modelClass:%@", NSStringFromClass(cls)],
                    NSLocalizedFailureReasonErrorKey : @"",
                    MTLTransformerErrorHandlingInputValueErrorKey : modelArray
            };

    *error = [NSError errorWithDomain:MTLTransformerErrorHandlingErrorDomain
                                 code:MTLTransformerErrorHandlingErrorInvalidInput
                             userInfo:userInfo];
}

void JSONToModelError(Class cls, NSError **error, id json) {
    NSDictionary *userInfo =
            @{
                    NSLocalizedDescriptionKey : [NSString stringWithFormat:@"JSON转Model失败, modelClass:%@", NSStringFromClass(cls)],
                    NSLocalizedFailureReasonErrorKey : @"",
                    MTLTransformerErrorHandlingInputValueErrorKey : json
            };

    *error = [NSError errorWithDomain:MTLTransformerErrorHandlingErrorDomain
                                 code:MTLTransformerErrorHandlingErrorInvalidInput
                             userInfo:userInfo];
}

void ModelToJsonError(Class cls, NSError **error, id model) {
    NSDictionary *userInfo =
            @{
                    NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Model转JSON失败, modelClass:%@", NSStringFromClass(cls)],
                    NSLocalizedFailureReasonErrorKey : @"",
                    MTLTransformerErrorHandlingInputValueErrorKey : model
            };

    *error = [NSError errorWithDomain:MTLTransformerErrorHandlingErrorDomain
                                 code:MTLTransformerErrorHandlingErrorInvalidInput
                             userInfo:userInfo];
}

@implementation LLModel

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{@"code" : @"code",
            @"success" : @"success",
            @"msg" : @"msg"};
}

+ (NSValueTransformer *)codeJSONTransformer {
    return [NSValueTransformer valueTransformerForName:MTLCommonValueTransformerName];
}

+ (NSValueTransformer *)successJSONTransformer {
    return [NSValueTransformer valueTransformerForName:MTLCommonValueTransformerName];
}

+ (NSValueTransformer *)msgJSONTransformer {
    return [NSValueTransformer valueTransformerForName:MTLCommonValueTransformerName];
}

@end
